//var server = '正式环境地址';
var baseurl = (("undefined" != typeof(server) && server == 'localhost') || document.domain.indexOf('localhost') !=-1) ? 'http://localhost:8099/mvn/' : '';

var loginurl = baseurl+'pages/login/login.html';
var myurl = baseurl+'pages/my/my_info.html';

//6-16位字母,数字组合不包含特殊符号
var checkpwd = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;

//底部菜单栏
$(document).ready(function(){
    $(".footer").load(baseurl+'pages/_include/footer.html'); 
});

function jumpPage(page){
    switch(page){
        case 0:
            href('../trans_query/order_enquiry_today.html?page=0');
            break;
        case 1:
            href('../bill/history_bill_day.html?page=1');
            break;
        case 2:
            href('../merchant_services/merchant.html?page=2');
            break;
        case 3:
            href('../my/my_info.html?page=3');          
            break;
    }
}

/**
* ajax 检查登录状态
* 跳转到登录页
*/
function checklogin(){
    var uid = localStorage.userId;
    if (typeof uid == 'undefined'){
        href(loginurl);
        return false;
    }else{
        href(myurl);
        return true;
    }
}

var wait = 60;
function timeout(o) {
   if (wait == 0) {
       $(o).attr("disabled", false);
       $(o).val("获取验证码");
       wait = 60;
   } else {
       $(o).attr("disabled", true);
       $(o).val(wait + "s后重发");
       wait--;
       setTimeout(function () {timeout(o);},1000);
   }
}

function os(){
    var ua = navigator.userAgent.toLowerCase(); 
    if(ua.match(/iPad/i)=="ipad" || ua.match(/iphone os/i) == "iphone os"){
		return 'ios';
	}else if (ua.match(/android/i) == "android") { 
       return 'android';
    }else if(ua.match(/micromessenger/i) == "micromessenger"){
		return 'wechat';
	}else if(ua.match(/msie 10/i) == "msie 10"){
		return 'ie10';
	}else { 
       return ''; 
    }
}

function Dbug(a){
    window.onerror = function(e, ee, line) {
        if (a) alert(e+ '：' +ee+ '：' +line);
    }
}

function iswechat(){
    var ua = navigator.userAgent.toLowerCase(); 
     return ua.match(/micromessenger/i) == "micromessenger";
}

function request(strParame) { 
	var args = new Object( ); 
	var query = location.search.substring(1); 
	
	var pairs = query.split("&"); // Break at ampersand 
	for(var i = 0; i < pairs.length; i++) { 
	var pos = pairs[i].indexOf('='); 
	if (pos == -1) continue; 
	var argname = pairs[i].substring(0,pos); 
	var value = pairs[i].substring(pos+1); 
	value = decodeURIComponent(value); 
	args[argname] = value; 
	} 
	return args[strParame]; 
} 

function zy_for(e, cb){
	var ch;
	if(e.currentTarget)
    	ch = e.currentTarget.previousElementSibling;
	else
		ch = e.previousElementSibling;
    if (ch.nodeName == "INPUT") {
        if (ch.type == "checkbox") 
            ch.checked = !ch.checked;
        if (ch.type == "radio" && !ch.checked) 
            ch.checked = "checked";
        
    }
    if (cb) 
        cb(e, ch.checked);
}

function nopic(src) {
    var npic = src || 'css/images/nopic.png';
    return document.domain ? domin + '/css/images/nopic.png': npic;

}

function getjsfile(js) {
    var oHead = document.getElementsByTagName('HEAD').item(0);
    var oScript = document.createElement("script");
    oScript.type = "text/javascript";
    oScript.src = js;
    oHead.appendChild(oScript);
}

function href(url, t) {
    setTimeout(function(){
        window.location.href = url;
	},t | 5);
}

	
function hz(str) {
    return encodeURIComponent(escape(str));
}

function uhz(str){
    return decodeURIComponent(unescape(str));	
}

function isnull(str) {
    return (str == null || str == 'null' || typeof(str) == "undefined" || str == '' || countnum(str) == 0);
}

function isnull2str(str, str2) {
    return ! isnull(str) ? str: str2;
}

function isArray(obj) {
    return typeof(obj) === 'object';
}

//返回上页, 后退
function goback(url) {
	
	if (document.referrer){
        window.history.go(-1);
	}else{
		href(url);
	}
    //history.go(-1);
}

function getarr(str, i, p) {
    var arr = str.split(p || ',');
    return arr[i];
}

function loadinit(t, str) {
    var z = $('#loadinit2');
    if (t == -1) { z.remove();
    } else if (t > 0) {
        setTimeout(function() { z.remove();
        },
        t);
    } else {
        
		//$('#loadinit2').remove();
		if (z.length > 0) return false;
		var w = parseInt($('body').css('font-size')) * 2;
		var l = Math.floor(($(window).width() - w) / 2);
		var b = $('<div id="loadinit2" class="ub-pc ub"><div class="bg ub tx-middle"><div class=load></div><div class="ub-f1 ulev-1">'+str+'</div></div></div>');
		$('body').append(b);
		if (t) setTimeout(function() {
			b.remove()
		},
		t);
        
    }
}

function alert_info(t, time, time2) {
    var c = $("#alert_info");
	var isscroll = $(document).height() - $(window).height();
	var topstyle = isscroll ? ' style="top:'+($(window).height()/2+$(document).scrollTop())+'px"' : ''
    if (c.length == 0) {
        var b = $('<div id="alert_info"'+topstyle+'><div class="alert_ub ub-pc ub"><div class=bg>' + t + '</div></div></div>');
        $('body').append(b);
    } else {
        c.html('<div class="alert_ub ub-pc ub"><div class=bg>' + t + '</div></div>')
    }

    if (time && c) {
        setTimeout(function() {

            $("#alert_info").fadeOut(time2 ? time2: 1000,
            function() {
               $(this).remove();
                
            });
        },
        time);

    }
}

function Xalert(str, time) {
    if (str == 'close') {
        $('#alert_info').remove();
    } else {
        alert_info(str, time);
    }
}


function countnum(dd) {
    if (typeof(dd) == "object") {
        var c = 0;
        for (var i in dd) {
            c++;
        }
        return c;
    } else {
        return dd.length;
    }
}

/*判断json数组是否存在某个元素*/
function in_json(key, json){ 
	$.each(json,function(i,v) {    
		if (v == key) {    
		return true;    
		}    
	}); 
	return false;
}

function in_array(e, data){
	for(i=0;i<data.length;i++){
		if(data[i] == e)
		    return true;
		}
	return false;
}


function nowtime(nos) {
    var date = new Date(); //日期对象
    var now = "";
    now = date.getFullYear() + "-"; //读英文就行了
    now = now + (date.getMonth() + 1) + "-"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
    now = now + date.getDate() + " ";
    now = now + date.getHours() + ":";
    now = now + date.getMinutes();
    if (!nos) now = now + ":" + date.getSeconds();
    return now;
}

function UnixTime(t) {
    var time = new Date().getTime();
    if (t) time = Math.round(time / 1000);
    return time
}

function Unix2Time(nS, t, tt) {
    var tm = new Date(parseInt(nS) * t);
    if (tt) tm = tm.toLocaleString().replace(/:d{1,2}$/, ' ');
    return tm;
}


function getDateDiff(dateTimeStamp) {
	var text = '';
	dateTimeStamp = parseInt(dateTimeStamp);
    var time = UnixTime(1);
	var datetime = Unix2Time(dateTimeStamp, 1000)
    var t = time - dateTimeStamp; //时间差 （秒）
    var y = Unix2Time(time, 1000).getFullYear() - datetime.getFullYear();
    var hms = datetime.format('h:m:s');
    if(t <= 60){
    		text = '刚刚'; // 一分钟内
	}else if(t < 60 * 60){
    		text = Math.floor(t / 60) + '分钟前';
   }else if(t < 60 * 60 * 24){
    		text = Math.floor(t / (60 * 60)) + '小时前';
   }else if(t < 60 * 60 * 24 * 3){
    		text = Math.floor(time/(60*60*24)) ==1 ?'昨天 ' + hms : '前天 ' + hms;
   }else if(t < 60 * 60 * 24 * 30){
    		text = datetime.format('MM-dd hh:mm'); //一个月内
   }else if(t < 60 * 60 * 24 * 365&&y==0){
    		text = datetime.format('MM-dd'); //一年内
   }else{
    		text = datetime.format('yyyy-MM-dd'); //一年以前
    }
	return text;
}

//格式化时间
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1,
        //month 
        "d+": this.getDate(),
        //day 
        "h+": this.getHours(),
        //hour 
        "m+": this.getMinutes(),
        //minute 
        "s+": this.getSeconds(),
        //second 
        "q+": Math.floor((this.getMonth() + 3) / 3),
        //quarter 
        "S": this.getMilliseconds() //millisecond 
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

Date.prototype.DateAdd = function(strInterval, Number) 
{ 
var dtTmp = this; 
switch (strInterval) { 
case 's' :return new Date(Date.parse(dtTmp) + (1000 * Number)); 
case 'n' :return new Date(Date.parse(dtTmp) + (60000 * Number)); 
case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * Number)); 
case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * Number)); 
case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number)); 
case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); 
case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); 
case 'y' :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); 
} 
} 

function StringAs(string) {
    return '"' + string.replace(/(\\|\"|\n|\r|\t)/g, "\\$1") + '"';
}

function isEmail(str){
  var reg = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;
  return reg.test(str);
}

function isMobile(str){
  var reg = /^1[3|5|7|8]\d{9}$/;
  return reg.test(str);
}

/*图片尺寸自适应*/
function Ximgsize(maxWidth, maxHeight, w, h) {

    var hRatio;
    var wRatio;
    var Ratio = 1;
    wRatio = maxWidth / w;
    hRatio = maxHeight / h;
    if (maxWidth == 0 && maxHeight == 0) {
        Ratio = 1;
    } else if (maxWidth == 0) { //
        if (hRatio < 1) Ratio = hRatio;
    } else if (maxHeight == 0) {
        if (wRatio < 1) Ratio = wRatio;
    } else if (wRatio < 1 || hRatio < 1) {
        Ratio = (wRatio <= hRatio ? wRatio: hRatio);
    }
    if (Ratio < 1) {
        w = w * Ratio;
        h = h * Ratio;
    }
    return {
        'w': w,
        'h': h
    };

}

function RndNum(n) {
    var rnd = "";
    for (var i = 0; i < n; i++) rnd += Math.floor(Math.random() * 10);
    return rnd;
}

function touch_hover(c){
	var t = event.currentTarget;
	$(t).Touchx({
		hoverClass: c
	});
}

